/*
 * Spring 2012 TCSS360 Deliverable 3
 * Otis Alexander
 */

package model;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;

public class Auction {

	private String my_auctionName;

	private Map<Integer, Item> my_items;

	private String my_npo;

	private String my_npoPhone;

	private Date my_auctionDate;

	private double my_startTime;

	private double my_endTime;

	private int my_numberOfItems;

	private String my_comments;

	private int my_ID;

	private boolean item_added;

	public Auction(final String npoName,
			final String npoPhone, final Date auctionDate,
			final double startTime, final double endTime,
			final int numberOfItems, final String comments,
			final int ID) {
		my_items = new HashMap<Integer, Item>();
		Calendar c = new GregorianCalendar();
		c.setTime(auctionDate);
		my_auctionName =
				npoName
						+ "-"
						+ c.getDisplayName(Calendar.MONTH,
								2, Locale.ENGLISH) + "-"
						+ c.get(Calendar.DAY_OF_MONTH)
						+ "-" + c.get(Calendar.YEAR);
		my_npo = npoName;
		my_npoPhone = npoPhone;
		my_auctionDate = auctionDate;
		my_startTime = startTime;
		my_endTime = endTime;
		my_numberOfItems = numberOfItems;
		my_comments = comments;
		my_ID = ID;
		item_added = false;
	}

	/**
	 * Adds an item to an auction's list of items.
	 * 
	 * @pre itemName != null
	 * @pre minBid != null
	 */
	public void addItem(final String itemName,
			final int quantity, final BigDecimal minBid,
			final String condition, final String comment) {
		Item i =
				new Item(itemName, quantity, minBid,
						condition, comment, my_npo,
						my_items.size() + 1);
		my_items.put(i.getID(), i);
		item_added = true;
	}

	public Item getItem(final int id) {
		return my_items.get(id);
	}

	public List<Item> getItems() {
		List<Item> items = new ArrayList<Item>();
		Iterator<Entry<Integer, Item>> list_it =
				my_items.entrySet().iterator();

		while (list_it.hasNext()) {
			Entry<Integer, Item> get_items_it =
					list_it.next();
			items.add(get_items_it.getValue());
		}
		return items;
	}

	public Date getDate() {
		return my_auctionDate;
	}

	public double getStartTime() {
		return my_startTime;
	}

	public double getEndTime() {
		return my_endTime;
	}

	public String getNPO() {
		return my_npo;
	}

	public String getPhone() {
		return my_npoPhone;
	}

	public String getName() {
		return my_auctionName;
	}

	public int getNumberOfItems() {
		return my_numberOfItems;
	}

	public int getNumberOfAddedItems() {
		return my_items.size();
	}

	public String getComment() {
		return my_comments;
	}

	public int getID() {
		return my_ID;
	}

	public boolean getItemAdded() {
		return item_added;
	}

	public void setItemAdded() {
		item_added = false;
	}
}
